//
//  OrgDB.swift
//  test-ios
//
//  Created by wyz5204 on 2023/6/5.
//

import Foundation
import GRDB

struct OrgDBEntity : DBEntity{
    
    static var databaseTableName: String = "table_org_bean"
    
    var _id : Int64 = -1
    let owner : String
    let orgName : String
    let id : Int
    let orgCode : Int
    
    init(id : Int , orgName : String , orgCode : Int , owner : String) {
        self.id = id
        self.orgName = orgName
        self.orgCode = orgCode
        self.owner = owner
    }
    
    mutating func didInsert(with rowID: Int64, for column: String?) {
        print("didInsert , rowID = \(rowID) , column = \(column)")
        self._id = rowID
    }
    
    
    func encode(to container: inout PersistenceContainer) {
//        container["_id"] = _id
        container["owner"] = owner
        container["orgName"] = orgName
        container["id"] = id
        container["orgCode"] = orgCode
    }
    
    init(row: Row) {
        print("create 1 " ,row)
        _id         = row["_id"]
        owner       = row["owner"]
        orgName     = row["orgName"]
        id          = row["id"]
        orgCode     = row["orgCode"]
        print("create 2 " ,row)
    }
}
